Only initialize test buffers once
authorØyvind Kolås <pippin@gimp.org>
Sun, 29 Nov 2009 15:42:05 +0000 (15:42 +0000)
committerØyvind Kolås <pippin@gimp.org>
Sun, 29 Nov 2009 15:45:11 +0000 (15:45 +0000)
Also made the test buffer static inline for individual conversions like
it already was for fish paths.

Note, this relies on none of the tested conversions by accident
being buggy enough to modify their source data, adding a sanity
function that compares the buffers with the correct values could
perhaps be useful.

babl/babl-conversion.c
babl/babl-fish-path.c

index e08b2e653243a5e78e48764ba8e79485fbc37569..422e2dda21bf17db326a8203ac3c17c1c87c816b 100644 (file)
@@ -420,18 +420,23 @@ babl_conversion_process (Babl *babl,
 
 #define test_pixels    512
 
+
 static double *
 test_create (void)
 {
-  double *test;
-  int     i;
+  static double test[sizeof (double) * test_pixels * 4];
+  int           i;
+  static int done = 0;
 
-  srandom (20050728);
+  if (done)
+    return test;
 
-  test = babl_malloc (sizeof (double) * test_pixels * 4);
+  srandom (20050728);
 
   for (i = 0; i < test_pixels * 4; i++)
     test [i] = (double) random () / RAND_MAX;
+
+  done = 1;
   return test;
 }
 
@@ -548,7 +553,6 @@ babl_conversion_error (BablConversion *conversion)
   babl_free (destination_rgba_double);
   babl_free (ref_destination);
   babl_free (ref_destination_rgba_double);
-  babl_free (test);
 
   conversion->error = error;
   conversion->cost  = babl_process_cost (ticks_start, ticks_end);
index d0932f37c1450b3a6a56ba068418c8a6cdc07d19..2622cb33d8a74254c00d3c934e722b87163a8491 100644 (file)
@@ -465,6 +465,10 @@ test_create (void)
 {
   static double test[sizeof (double) * NUM_TEST_PIXELS * 4];
   int           i, j;
+  static int    done = 0;
+
+  if (done)
+    return test;
 
   /* There is no need to generate the test
    * more times ... */
@@ -483,6 +487,7 @@ test_create (void)
   for (j = 0; j < 16 * 4; i++, j++)
     test [i] = 1.0 + (double) random () / RAND_MAX;
 
+  done = 1;
   return test;
 }